<html>
<head><meta charset="utf-8"><title>sourcemap loading · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/sourcemap.20loading.html">sourcemap loading</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="218139944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/sourcemap%20loading/near/218139944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/sourcemap.20loading.html#218139944">(Nov 28 2020 at 01:07)</a>:</h4>
<p>Where is the sourcemap created? Specifically, I'm wondering how rustc knows what files it needs to load since I think it knows before it has figured out which modules are declared. Does it just glob-load <code>*.rs</code> files? Thanks!</p>



<a name="218159179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/sourcemap%20loading/near/218159179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/sourcemap.20loading.html#218159179">(Nov 28 2020 at 10:59)</a>:</h4>
<p>The parser requests the source files from the <code>SourceMap</code> using <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/source_map/struct.SourceMap.html#method.load_file"><code>SourceMap::load_file</code></a> in <a href="https://github.com/rust-lang/rust/blob/4ae328bef47dffcbf363e5ae873f419c06a5511d/compiler/rustc_parse/src/lib.rs#L151"><code>try_file_to_source_file</code></a>. <code>SourceMap::load_file</code> in turn uses the <code>FileLoader</code> of the compilation session to load the source file. The default <code>FileLoader</code> reads directly from the disk.</p>



<a name="218186329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/sourcemap%20loading/near/218186329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/sourcemap.20loading.html#218186329">(Nov 28 2020 at 23:35)</a>:</h4>
<p>Ah, so the files aren't loaded ahead-of-time?</p>



<a name="218186383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/sourcemap%20loading/near/218186383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/sourcemap.20loading.html#218186383">(Nov 28 2020 at 23:36)</a>:</h4>
<p>no, that wouldn't work</p>



<a name="218186387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/sourcemap%20loading/near/218186387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/sourcemap.20loading.html#218186387">(Nov 28 2020 at 23:36)</a>:</h4>
<p>you could have <code>#[path = "Z:\whatever.rs"]</code></p>



<a name="218186391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/sourcemap%20loading/near/218186391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/sourcemap.20loading.html#218186391">(Nov 28 2020 at 23:37)</a>:</h4>
<p>there's no way to preload that</p>



<a name="218232802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/sourcemap%20loading/near/218232802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/sourcemap.20loading.html#218232802">(Nov 29 2020 at 21:58)</a>:</h4>
<p>Ah, I haven't heard of that attribute.</p>



<a name="218232815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/sourcemap%20loading/near/218232815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/sourcemap.20loading.html#218232815">(Nov 29 2020 at 21:58)</a>:</h4>
<p>If we didn't allow loading from an arbitrary path, could we load all the <code>*.rs</code> files in the <code>src</code> directory in advance?</p>



<a name="218232825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/sourcemap%20loading/near/218232825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/sourcemap.20loading.html#218232825">(Nov 29 2020 at 21:59)</a>:</h4>
<p>(i.e. in the driver)</p>



<a name="218233092"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/sourcemap%20loading/near/218233092" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/sourcemap.20loading.html#218233092">(Nov 29 2020 at 22:05)</a>:</h4>
<p>I think so</p>



<a name="218233093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/sourcemap%20loading/near/218233093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/sourcemap.20loading.html#218233093">(Nov 29 2020 at 22:05)</a>:</h4>
<p>It's what rust-analyzer does</p>



<a name="218233102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/sourcemap%20loading/near/218233102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/sourcemap.20loading.html#218233102">(Nov 29 2020 at 22:06)</a>:</h4>
<p>and so far that only falls short when <code>#[path]</code> is involved, which is why <code>std::arch</code> doesn't get completed</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>